fix(types): add type declarations for the rclnodejs/rosocket subpath#1533
Merged
Conversation
The ./rosocket subpath export shipped no type declarations, so under
node16/nodenext resolution `import { startRosocket } from 'rclnodejs/rosocket'`
failed with TS7016 (implicit any) and @arethetypeswrong reported 'No types'.
- add rosocket/index.d.ts typing the public entry point (startRosocket,
StartRosocketOptions, RosocketServer), matching rosocket/index.js.
- add a rosocket/index.d.cts companion so the require condition resolves
to a CommonJS-format type file (no 'Masquerading as ESM').
- wire per-condition types into the ./rosocket export.
attw now reports rclnodejs/rosocket green across node10, node16 (CJS+ESM)
and bundler; tsd passes and a nodenext+strict consumer resolves the
subpath without TS7016.
There was a problem hiding this comment.
Pull request overview
This PR adds TypeScript declaration support for the rclnodejs/rosocket subpath export so that node16/nodenext consumers can import it without TS7016 and type tools detect the subpath as typed.
Changes:
- Added
rosocket/index.d.tsdescribing the publicstartRosocket()API and its option/return shapes. - Added
rosocket/index.d.ctsas a CommonJS-facing type entrypoint for therequireexport condition. - Updated
package.jsonexports["./rosocket"]to provide per-conditiontypesentries for bothimportandrequire.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| rosocket/index.d.ts | Adds ESM type declarations for the rclnodejs/rosocket public API. |
| rosocket/index.d.cts | Adds CJS type entrypoint intended to satisfy the require export condition. |
| package.json | Wires conditional types paths into the ./rosocket export map. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
28
to
+32
| "./rosocket": { | ||
| "import": "./dist/rosocket.js", | ||
| "require": "./dist/rosocket.cjs", | ||
| "import": { | ||
| "types": "./rosocket/index.d.ts", | ||
| "default": "./dist/rosocket.js" | ||
| }, |
Comment on lines
+1
to
+6
| // CommonJS type entry for `require('rclnodejs/rosocket')`. | ||
| // | ||
| // Re-exports the ESM declarations so the `require` condition has a CommonJS | ||
| // (`.d.cts`) type file whose module format matches the CommonJS JavaScript | ||
| // served by the same condition. | ||
| export * from './index.js'; |
Address Copilot review on RobotWebTools#1533: add the standard Apache-2.0 license header to rosocket/index.d.cts to match the other shipped type entrypoints (web/index.d.ts, lib/runtime/index.d.ts, rosocket/index.d.ts).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
./rosocketsubpath export shipped no type declarations, so undernode16/nodenextmodule resolution:import { startRosocket } from 'rclnodejs/rosocket'failed with TS7016 (the module implicitly had ananytype).@arethetypeswrongreported No types for the subpath across every resolution mode.Changes
rosocket/index.d.ts— types the public entry point (startRosocket,StartRosocketOptions,RosocketServer), matched againstrosocket/index.js(port=9000,host='0.0.0.0', requirednode, returns{ wss, close, port }).wssis typed as itsEventEmittersupertype to avoid a hard dependency onwstypes.rosocket/index.d.cts— a CommonJS-format companion (re-exporting the.d.ts) so therequirecondition resolves to a CJS type file and is not flagged as "Masquerading as ESM".typesinto the./rosocketexport inpackage.json(import→index.d.ts,require→index.d.cts).Fix: #1532